home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *
- * NSSDC/CDF CDFwalk. Part 1 or 2.
- *
- * Version 2.0, 4-Mar-92, ST Systems (STX)
- *
- * Modification history:
- *
- * V1.0 25-Jul-91, H Leckner Original version (for CDF V2.1).
- * V1.0a 5-Aug-91, J Love Fixed value input.
- * V1.1 20-Sep-91, J Love Modified for IBM-PC port.
- * V1.2 11-Oct-91, H Leckner Changed for IBM-RS6000 port.
- * V1.3 18-Oct-91, H Leckner More changes for IBM-RS6000 port (and fixed
- * variable name field).
- * V1.3a 22-Oct-91, J Love Got the right version this time.
- * V2.0 4-Mar-92, J Love IBM PC port. CDF V2.2.
- *
- ******************************************************************************/
-
- #include "wfl.h"
-
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <ctype.h>
-
- #if defined(unix)
- #include <sys/types.h>
- #include <sys/stat.h>
- extern char *getenv();
- #else
- #if defined (vms)
- #include <descrip.h>
- #else
- #if defined(__MSDOS__)
- #include <dos.h>
- #endif
- #endif
- #endif
- #define CDFWALK 1
- #include "cdfdist.h"
- #include "kb_def.h"
- #include "utility.h"
- #include "cdfwalk.h"
-
- #if defined(vms)
- main (argc, argv)
- #else
- void main (argc, argv)
- #endif
- int argc;
- char *argv[];
- {
- static struct CDF_struct CDF;
- static struct GLOBAL_struct screen;
- struct variable_struct *variables;
- struct vid_struct *VAR_display;
- union mixed *data_values;
- CDFstatus rcode;
- long int i;
- long int CDF_is_OPEN = FALSE;
- static char open_mes[] = "Opening CDF...";
- /*FILE *fptr;*/
- long int field_num;
- long int exit_code;
- int tcode;
- long int cdf_input = MANUAL;
- char temp[CDF_PATHNAME_LEN];
- char help_file_name[80];
- #if defined(unix) || defined(__MSDOS__)
- char *s;
- #endif
- QOP *qop;
- static char *validQuals[] = { NULL };
- for (i=0; i < CDF_NAME_LENGTH; i++)CDF.CDF_name[i] = '\0';
-
- qop = Qop (argc, argv, validQuals, NULL);
- if (qop == NULL) ExitBAD;
- switch (qop->Nparms) {
- case 0:
- strcpy(CDF.CDF_name, default_name);
- break;
- case 1:
- cdf_input = AUTO;
- strcpy(CDF.CDF_name, qop->parms[0]);
- strcpy(temp, qop->parms[0]);
- strcat(temp,".cdf");
- if(!IsReg(temp))cdf_input = DIRECTORY;
- break;
- default:
- printf ("Too many parameters.\n");
- ExitBAD;
- }
- field_num = 1;
- rcode = init_var_display(&VAR_display);
- if(rcode != 0)ExitBAD;
- CDFWALK_open_screen(&screen);
-
- HELP_ptr = NULL;
- #if defined(unix)
- s = getenv("CDF_HELP");
- if(s)
- {
- strcpy(help_file_name, s);
- strcat(help_file_name, "/cdfwalk.hlp");
- }
- else
- strcpy(help_file_name, "../help/cdfwalk.hlp");
- #endif
- #ifdef vms
- strcpy(help_file_name,"CDF$HELP:cdfwalk.hlp");
- #endif
- #if defined(__MSDOS__)
- s = getenv("CDF_HELP");
- if(s)
- {
- strcpy(help_file_name, s);
- strcat(help_file_name, "\\cdfwalk.hlp");
- }
- else
- strcpy(help_file_name, ".\\cdfwalk.hlp");
- HELP_ptr = fopen(help_file_name, "r");
- if(HELP_ptr == NULL)
- {
- strcpy(help_file_name, "c:\\cdf22\\help\\cdfwalk.hlp");
- HELP_ptr = fopen(help_file_name, "r");
- }
- #endif
-
- variables = NULL;
- data_values = NULL;
-
- while(field_num != EXIT)
- {
- switch (field_num)
- {
- case CDF_FIELD:
- CDFWALK_put_selection(screen.CDF_vid, CDF_display,
- CDFNAME_ELEMENT_NUM-1, CDF.CDF_name, CDF_NAME_LENGTH-COL_OFFSET,
- REVERSE);
- if(cdf_input != AUTO)
- tcode = CDFWALK_CDF_name(&screen, &CDF, &field_num, &cdf_input);
- else
- {
- field_num = WALK_FIELD;
- tcode = CONTINUE;
- }
- if(tcode != QUIT && field_num != EXIT && strlen(CDF.CDF_name) > 0)
- {
- if(CDF_is_OPEN)
- {
- CDFWALK_close(&CDF, variables);
- free(data_values);
- }
- CDFWALK_put_message(screen.MES_vid, open_mes, NOBELL, BLINK,
- NOPAUSE);
- for (i=0; i < CDF_MAX_DIMS; i++)
- CDF.dim_var_num[i] = NOTTHERE;
- rcode = CDFWALK_open(&CDF, &variables, &data_values);
- cdf_input = MANUAL;
- if(rcode < CDF_OK || rcode == NODATA)
- {
- exit_code = print_error(&screen, rcode);
- if(exit_code == NOCONTINUE)field_num = CDF_FIELD;
- CDF_is_OPEN = FALSE;
- }
- else
- {
- CDF_is_OPEN = TRUE;
- CDFWALK_CDF_info(&screen, &CDF, CDF_display);
- CDFWALK_clear_row(screen.VAR_vid, VAR_display, 1, 54,
- VAR_COLUMNS-COL_OFFSET);
- CDFWALK_clear_row(screen.MES_vid, MES_display, 1, 1,
- MES_COLUMNS-COL_OFFSET);
- }
- }
- break;
- case WALK_FIELD:
- CDFWALK_list(&screen, &CDF, variables, VAR_display, data_values,
- &field_num);
- break;
- case HELP_FIELD:
- CDFWALK_help(&screen);
- CDFWALK_field_menu(&screen, &field_num);
- }
- }
- if(HELP_ptr != NULL)fclose(HELP_ptr);
- free(VAR_display);
- if(CDF_is_OPEN)CDFWALK_close(&CDF, variables);
- CDFWALK_close_screen();
- Exit;
- }
- long int print_error(screen, rcode)
- struct GLOBAL_struct *screen;
- CDFstatus rcode;
- {
- long int exit_code;
- char error_mes[CDF_ERRTEXT_LEN];
- if(rcode == NODATA)
- {
- exit_code = NOCONTINUE;
- strcpy(error_mes, "This CDF contains no records");
- }
- else
- {
- if(rcode < CDF_WARN)
- exit_code = NOCONTINUE;
- else if(rcode < CDF_OK)
- exit_code = CONTINUE;
- else if(rcode != CDF_OK)
- exit_code = CONTINUE;
- /*
- Get the error message
- */
- CDFerror(rcode, error_mes);
- }
- /*
- Print the message
- */
- CDFWALK_put_message(S.MES_vid, error_mes, RINGBELL, NORMAL, PAUSE);
- return(exit_code);
- }
- int alloc_all_dim(ptr, num_vars, num_dims)
- long int ***ptr;
- long int num_vars;
- long int num_dims;
- {
- long int i;
- long int num;
-
- if((*ptr = (long int **)
- malloc((CDF_MAX_DIMS+1) * sizeof(long int *))) == NULL)
- return(-1);
- else
- {
- num = num_vars > num_dims ? num_vars+1 : num_dims+1;
- for(i=0; i<num; i++)
- {
- if(((*ptr)[i] =
- (long int *) malloc(num * sizeof(long int))) == NULL)
- return(-1);
- }
- }
- return(0);
- }
- CDFstatus CDFWALK_open(CDF, variables, data_values)
- struct CDF_struct *CDF;
- struct variable_struct **variables;
- union mixed **data_values;
- {
- CDFstatus rcode;
- long int i,j;
- long int var_num;
- /*long int attr_num;*/
- long int dim_num;
- long int num_true;
- /*long int len;*/
- char temp[CDF_VAR_NAME_LEN];
-
- /*
- Open the CDF
- */
- rcode = CDFopen(C.CDF_name, &C.CDF_id);
- if(rcode < CDF_OK)return (rcode);
-
- rcode = CDFdoc(C.CDF_id, &C.version, &C.release, C.text);
-
- for(i=0; i<CDF_MAX_DIMS; i++)
- C.dim_sizes[i] = FALSE;
- /*
- Inquire about CDF structure
- */
- rcode = CDFinquire(C.CDF_id, &C.num_dims, C.dim_sizes, &C.encoding,
- &C.majority, &C.max_record_num, &C.num_vars, &C.num_attrs);
- if(rcode < CDF_OK)
- return(rcode);
- else if(C.max_record_num < 0)
- /*
- CDF contains no data, nothing to WALK thru
- */
- return(NODATA);
- *variables = (struct variable_struct *)
- malloc(C.num_vars * sizeof(struct variable_struct));
- if(*variables == NULL)return(BAD_MALLOC);
- rcode = alloc_all_dim(&C.all_dim_var_num, C.num_vars, C.num_dims);
-
- if(rcode != 0)ExitBAD;
- if(C.version == 1)
- {
- C.encoding = HOST_ENCODING;
- C.majority = ROW_MAJOR;
- }
- else if(C.encoding != NETWORK_ENCODING)
- C.encoding = HOST_ENCODING;
-
- C.num_scalars = 0;
- C.EPOCH_var_num = NOTTHERE;
- C.first_scalar_var_num = NOTTHERE;
- C.record_var_num = NOTTHERE;
- /*
- Initialize up to number of dimensions + 1 for the record number
- */
- for(i=0; i<C.num_dims+1; i++)
- {
- C.num_per_dim[i] = 0;
- for(j=0; j<C.num_vars; j++)
- C.all_dim_var_num[i][j] = 0;
- }
- /*
- Get all the variables in the CDF
- */
- for (var_num=0; var_num < C.num_vars; var_num++)
- {
- for(i=0; i<CDF_MAX_DIMS; i++)
- VN.dim_variances[i] = FALSE;
- for(i=0; i<CDFWALK_MAX_VAR_LENGTH; i++)VN.var_mnemonic[i] = ' ';
- rcode = CDFvarInquire(C.CDF_id, var_num, temp, &VN.data_type,
- &VN.num_bytes, &VN.record_variance, VN.dim_variances);
- if(rcode < CDF_OK)return (rcode);
- else
- {
- strncpy(VN.var_mnemonic, temp, CDFWALK_MAX_VAR_LENGTH);
- VN.var_mnemonic[CDFWALK_MAX_VAR_LENGTH] = '\0';
- VN.var_num = var_num;
- VN.dim_variable = FALSE;
- VN.record_variable = FALSE;
- VN.filter = FALSE;
- VN.scalar = SCALAR;
- VN.bin_value = NULL;
- VN.char_value = NULL;
- num_true=0;
- /*
- Check for a scalar or dimensionally variant variable
- */
- for (i=0; i< C.num_dims; i++)
- {
- if(VN.dim_variances[i] != NOVARY)
- {
- dim_num=i+1;
- num_true++;
- VN.scalar = FALSE;
- }
- }
- if(num_true == 1 && !VN.record_variance)
- {
- C.all_dim_var_num[dim_num][C.num_per_dim[dim_num]++] = var_num;
- VN.dim_num = dim_num;
- VN.num_values=C.dim_sizes[dim_num-1];
- }
- else
- {
- if(!VN.record_variance && num_true > 1)
- VN.dim_num = MULTIPLE;
- else
- VN.dim_num = 0;
- VN.num_values=0;
- }
- }
- if(VN.scalar)
- {
- C.all_dim_var_num[0][C.num_per_dim[0]++] = var_num;
- VN.num_values = C.max_record_num+1;
- }
- }/*var loop*/
-
- *data_values = (union mixed *) malloc(C.num_vars * sizeof(union mixed));
- if(*data_values == NULL)return(BAD_MALLOC);
-
- return (rcode);
- }
- void CDFWALK_load_dim(CDF, variables, DIM_display, dim_num, num_rows)
- struct CDF_struct *CDF;
- struct variable_struct variables[];
- struct vid_struct *DIM_display;
- long int dim_num;
- int *num_rows;
- {
- long int i;
-
- for(i=0; i<C.num_per_dim[dim_num]; i++)
- {
- DIM_display[i].row = 1;
- DIM_display[i].col = 1;
- strcpy(DIM_display[i].label,
- variables[C.all_dim_var_num[dim_num][i]].var_mnemonic);
- }
- *num_rows = C.num_per_dim[dim_num]+ROW_OFFSET > DIM_ROWS ? DIM_ROWS :
- C.num_per_dim[dim_num]+ROW_OFFSET;
- }
- void CDFWALK_list(screen, CDF, variables, VAR_display, data_values,
- curr_field)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- struct variable_struct *variables;
- struct vid_struct *VAR_display;
- union mixed *data_values;
- long int *curr_field;
- {
- struct vid_struct *DIS_display;
- struct vid_struct *DIM_display;
- long int var_index = 0;
- long int var_num;
- long int val_num;
- long int num;
- /*long int num_elements;*/
- long int dim_num;
- long int field_num;
- long int col_field;
- int row /*,col*/ ;
- int tcode;
- /*long int found;*/
- long int record_num;
- long int indices[10];
- /*long int yr,mo,da,hr,min,sec,msec;*/
- char buf[7], /*buf2[7],*/ buf3[25];
- char temp[80];
- long int i;
- static char dim_number[] = "1234567890";
- static char record_error_mes[] =
- "Record number out of range, valid range is from 1 - ";
- static char indices_error_mes[] =
- "Index out of range, valid range is from 1 - ";
- static char input_error_mes[] =
- "Error detected in input string ";
- static char noscroll_mes[] =
- "All variables are currently displayed on screen";
- static char value_input_mes[] =
- "Enter desired value from variable ";
- static char EPOCH_input_mes[] =
- "Enter a desired time from the CDF ";
- static char record_input_mes[] =
- "Enter record number or a number preceded by +/- to increment or decrement";
- static char indices_input_mes[] =
- "Enter index number or a number preceded by +/- to increment or decrement";
- static char record_indices_mes[] =
- "Right/Left arrows to move +/- thru records/indices, I = input a record/index";
- static char value_mes[] =
- "Right/Left arrows=move +/- thru values,I=input value,CTL-P=select value popup";
- static char load_data_mes[] =
- "Loading data from CDF...";
- static char select_begin_mes[] =
- "Multiple variables describe ";
- static char select_end_mes[] =
- " select one for filtering/display";
- static char no_var_mes[] =
- "No variables in CDF describe ";
- static char to_many_mes[] =
- "This variable contains too many values to select from popup, select manually";
- static char scan_mes[] =
- "Scanning for selected data...";
- char mes[80];
- long int type;
- long int offset;
- /*long int EPOCH;*/
- int dis_rows, dis_cols;
- int dim_rows;
- long int num_bytes;
- long int value;
- double rvalue;
- long int update_keydef;
- long int rcode;
- int len;
- static long int offsets[2] = { 9, 46 };
- static long int lengths[2] = { 24, 6 };
- static long int scolumns[2] = { 33, 52 };
-
- create_virtual_display(C.num_dims+1+ROW_OFFSET, WALK_COLUMNS, &S.WALK_vid,
- BORDER, BOLD);
- #if !defined(vms)
- begin_display_update(S.WALK_vid);
- #endif
- put_chars(S.WALK_vid, "Record#", 7, 1, 39, ERASE, NORMAL);
- /*
- Now find the variables that vary with each dimension and place them on the screen
- */
- for(dim_num = 0; dim_num < C.num_dims; ++dim_num)
- {
- for(i=0; i<WALK_COLUMNS; i++)temp[i] = ' ';
- strcpy(temp, "Dimension");
- strncpy(temp+9, dim_number+dim_num, 1);
- put_chars(S.WALK_vid, temp, 11, dim_num+2, 36, ERASE, NORMAL);
- }
- paste_virtual_display(S.WALK_vid, WALK_ROW_PASTE, WALK_COL_PASTE);
- #if !defined(vms)
- end_display_update(S.WALK_vid);
- #endif
- label_border(S.WALK_vid, WALK_label, strlen(WALK_label));
- /*
- Choose a variable for record and each dimension to be displayed in the
- WALK window for each dimension if applicable
- */
- for(dim_num=0; dim_num<=C.num_dims; dim_num++)
- {
- if(C.num_per_dim[dim_num] > 0)
- {
- num = 1;
- if(C.num_per_dim[dim_num] > 1)
- {
- DIM_display = (struct vid_struct *)
- malloc(C.num_per_dim[dim_num] * sizeof(struct vid_struct));
- CDFWALK_load_dim(CDF, variables, DIM_display, dim_num, &dim_rows);
- #ifdef vms
- change_virtual_display(dim_rows, DIM_COLUMNS,
- S.DIM_vid, BORDER, BOLD);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- change_virtual_display(dim_rows,
- DIM_COLUMNS, &S.DIM_vid, BORDER, BOLD);
- #endif
- strcpy(mes, select_begin_mes);
- if(dim_num == 0)
- strcat(mes,"Record Number,");
- else
- {
- strcat(mes,"Dimension ");
- strncpy(mes+38, dim_number+(dim_num-1), 1);
- mes[39] = ',';
- mes[40] = '\0';
- }
- strcat(mes,select_end_mes);
- CDFWALK_put_message(S.MES_vid, mes, NOBELL, NORMAL, NOPAUSE);
-
- CDFWALK_Menu_keydef(screen);
- CDFWALK_select_menu_item(S.DIM_vid,
- S.MES_vid, &num, DIM_display, C.num_per_dim[dim_num],
- dim_rows, DIM_COLUMNS, DIM_ROW_PASTE, DIM_COL_PASTE, MENU, &tcode);
- free(DIM_display);
- } /* num_per_dim > 1 */
- /*
- Only one variable describes this variable or dimension
- */
- if(dim_num != RECORD)
- {
- var_num = C.all_dim_var_num[dim_num][num-1];
- C.dim_var_num[dim_num] = var_num;
- V.dim_variable = TRUE;
- }
- else
- {
- var_num = C.all_dim_var_num[RECORD][num-1];
- C.dim_var_num[RECORD] = var_num;
- V.record_variable = TRUE;
- }
- if(V.num_values <= MAX_VALUES)
- {
- if(V.data_type == CDF_EPOCH)
- {
- if((V.bin_value = (double *)
- malloc(V.num_values * sizeof(double))) == NULL)
- {
- printf("Error allocating EPOCH binary discrete ptr");
- ExitBAD;
- }
- if((V.char_value = (char *)
- malloc(V.num_values*EPOCH_WIDTH)) == NULL)
- {
- printf("Error allocating EPOCH character discrete ptr");
- ExitBAD;
- }
- /*
- Retrieve EPOCH values from CDF
- */
- CDFWALK_get_EPOCH(C.CDF_id, var_num, C.max_record_num,
- V.bin_value, V.char_value);
- }
- else if(V.data_type != CDF_CHAR && V.data_type != CDF_UCHAR)
- {
- if((V.bin_value = (double *)
- malloc(V.num_values * sizeof(double))) == NULL)
- {
- printf("Error allocating binary discrete ptr, %ld %ld ",
- var_num, V.num_values);
- ExitBAD;
- }
- if((V.char_value = (char *)
- malloc(V.num_values*MINMAX_SIZE)) == NULL)
- {
- printf("Error allocating character discrete ptr");
- ExitBAD;
- }
- /*
- Retrieve binary values from the CDF if variable describes a dimension
- */
- CDFWALK_get_discrete(C.CDF_id, dim_num, V.var_num, V.data_type,
- V.num_values, V.bin_value, V.char_value);
- }
- else
- {
- if((V.char_value = (char *)
- malloc(V.num_values*(V.num_bytes+1))) == NULL)
- {
- printf("Error allocating character discrete ptr");
- ExitBAD;
- }
- /*
- Retrieve character values from the CDF if variable describes a dimension
- */
- CDFWALK_get_discrete_char(C.CDF_id, dim_num, V.var_num,
- V.num_values, V.num_bytes, V.char_value);
- }
- } /* MAX_VALUES?? */
- len = strlen(V.var_mnemonic);
- if(len > CDFWALK_MAX_VAR_LENGTH)len = CDFWALK_MAX_VAR_LENGTH;
- put_chars(S.WALK_vid, V.var_mnemonic, len, dim_num+1,1,NOERASE,NORMAL);
- } /* num_dim > 0 */
- else
- {
- strcpy(mes, no_var_mes);
- if(dim_num == 0)
- strcat(mes,"Record Number ");
- else
- {
- strcat(mes,"Dimension ");
- strncpy(mes+39, dim_number+(dim_num-1), 1);
- mes[40] = '\0';
- }
- CDFWALK_put_message(S.MES_vid, mes, RINGBELL, NORMAL, PAUSE);
- }
- for(i=0; i<80; i++)mes[i] = ' ';
- }/*end dim loop*/
-
- CDFWALK_alloc_STRING(variables, C.num_vars, data_values);
-
- CDFWALK_put_message(S.MES_vid, load_data_mes, NOBELL, BLINK, NOPAUSE);
-
- update_keydef = TRUE;
- record_num = 0;
- for(dim_num=0; dim_num<C.num_dims; dim_num++)indices[dim_num] = 0;
- field_num = 0;
- if(C.num_per_dim[0] > 0)
- col_field = 0;
- else
- col_field = 1;
-
- while(*curr_field == WALK_FIELD)
- {
- sprintf(buf, "%6ld", record_num+1);
- put_chars(S.WALK_vid, buf, strlen(buf), 1, WALK_COLUMNS-5-COL_OFFSET,
- NOERASE, NORMAL);
- for(dim_num=0; dim_num<C.num_dims; dim_num++)
- {
- sprintf(buf, "%6ld", indices[dim_num]+1);
- row = dim_num + 2;
- put_chars(S.WALK_vid,buf, strlen(buf),row, WALK_COLUMNS-5-COL_OFFSET,
- NOERASE, NORMAL);
- }
- /*
- Retrieve the data for the current record and set of indices
- */
- CDFWALK_get_data(CDF, variables, C.num_vars, record_num, indices,
- data_values);
- /*
- Now display the current set of variables and data
- */
- CDFWALK_load_var(screen, CDF, variables, VAR_display, var_index,
- data_values);
-
-
- row = field_num + 1;
- if(col_field == 0)
- CDFWALK_put_message(S.MES_vid, value_mes, NOBELL, NORMAL, NOPAUSE);
- else
- CDFWALK_put_message(S.MES_vid, record_indices_mes, NOBELL, NORMAL,
- NOPAUSE);
- if(update_keydef)CDFWALK_walk_keydef(screen);
- update_keydef = FALSE;
- set_cursor_abs(S.WALK_vid, row, scolumns[col_field]);
-
- #ifdef vms
- read_input(&tcode);
- #endif
- #if defined(unix) | defined(ultrix) | defined(__MSDOS__)
- read_input(S.WALK_vid, &tcode);
- #endif
- switch (tcode)
- {
- case KB_RIGHTARROW:
- /*
- Increment the record number
- */
- if(field_num == 0)
- {
- record_num++;
- if(record_num > C.max_record_num)record_num = 0;
- }
- else
- /*
- Increment the current dimension indice
- */
- {
- indices[field_num-1]++;
- if(indices[field_num-1] ==
- C.dim_sizes[field_num-1])indices[field_num-1]=0;
- }
- break;
- case KB_LEFTARROW:
- /*
- Decrement the record number
- */
- if(field_num == 0)
- {
- record_num--;
- if(record_num < 0)record_num = C.max_record_num;
- }
- else
- /*
- Decrement the current dimension indice
- */
- {
- indices[field_num-1]--;
- if(indices[field_num-1] < 0)
- indices[field_num-1]=C.dim_sizes[field_num-1]-1;
- }
- break;
- case KB_UPARROW:
- /*
- Move up to record or dimension on the screen
- */
- field_num--;
- if(field_num < 0)field_num = C.num_dims;
- if(C.num_per_dim[field_num] == 0)col_field = 1;
- break;
- case KB_DOWNARROW:
- /*
- Move down to record or dimension on the screen
- */
- field_num++;
- if(field_num > C.num_dims)field_num = 0;
- if(C.num_per_dim[field_num] == 0)col_field = 1;
- break;
- case KB_RETURN:
- case KB_PAD_ENTER:
- col_field++;
- if(col_field > 1)
- {
- col_field = 0;
- field_num++;
- if(field_num > C.num_dims)field_num = 0;
- if(C.num_per_dim[field_num] == 0)col_field = 1;
- }
- break;
- case KB_BACKFIELD:
- col_field--;
- if(col_field < 0)
- {
- col_field = 1;
- field_num--;
- if(field_num < 0)field_num = C.num_dims;
- }
- else if(C.num_per_dim[field_num] == 0)
- col_field = 1;
- break;
- case INPUT:
- case input:
- var_num = C.dim_var_num[field_num];
- /*
- Input a record number or indice
- */
- read_display(S.WALK_vid, row, temp);
- strncpy(buf3, temp+offsets[col_field],lengths[col_field]);
- buf3[lengths[col_field]] = '\0';
- CDFWALK_left_justify(buf3);
- if(V.data_type == CDF_EPOCH && col_field == 0)
- label_border(S.WALK_vid, WALK_EPOCH_label,
- strlen(WALK_EPOCH_label));
- put_chars(S.WALK_vid, buf3, strlen(buf3), row,
- offsets[col_field]+1, NOERASE, REVERSE);
- if(col_field == 0)
- {
- if(V.data_type == CDF_EPOCH)
- strcpy(mes, EPOCH_input_mes);
- else
- {
- strcpy(mes, value_input_mes);
- strcat(mes, V.var_mnemonic);
- }
- CDFWALK_put_message(S.MES_vid, mes, NOBELL, NORMAL,
- NOPAUSE);
- }
- else
- {
- if(field_num == 0)
- CDFWALK_put_message(S.MES_vid, record_input_mes,
- NOBELL, NORMAL, NOPAUSE);
- else
- CDFWALK_put_message(S.MES_vid, indices_input_mes,
- NOBELL, NORMAL, NOPAUSE);
- }
- input_field(S.WALK_vid, buf3,
- row, offsets[col_field]+1, lengths[col_field], &tcode);
- if(col_field == 0)
- {
- /*
- Input actual value
- */
- if(V.data_type != CDF_CHAR && V.data_type != CDF_UCHAR)
- {
- if(V.data_type == CDF_EPOCH)
- rcode = check_epoch(buf3, &rvalue);
- else
- rcode = sscanf(buf3, "%lf", &rvalue); /*V1.0a*/
- /*
- Retrieve closest indice
- */
-
- if(rcode == 0)
- CDFWALK_put_message(S.MES_vid, input_error_mes,
- RINGBELL, NORMAL, PAUSE);
- else
- {
- CDFWALK_put_message(S.MES_vid, scan_mes,
- NOBELL, BLINK, NOPAUSE);
- value = CDFWALK_get_index(C.CDF_id, V.dim_num,
- V.var_num, rvalue, V.data_type,
- V.bin_value, V.num_values);
- }
- }
- else
- {
- CDFWALK_put_message(S.MES_vid, scan_mes,
- NOBELL, BLINK, NOPAUSE);
- value = CDFWALK_get_index_char(C.CDF_id, V.dim_num,
- V.var_num, buf3, V.num_bytes, V.char_value,
- V.num_values);
- }
- type = NORMAL;
- }
- else
- /*
- Input record number or indice
- */
- {
- if(strchr(buf3, '+'))
- /*
- inputing a + in the first character causes the value to be incremented
- by the specified amount
- */
- {
- type = INCREMENT;
- offset = 1;
- }
- else if(strchr(buf3, '-'))
- /*
- inputing a - in the first character causes the value to be incremented
- by the specified amount
- */
- {
- type = DECREMENT;
- offset = 1;
- }
- else
- {
- type = NORMAL;
- offset = 0;
- }
- rcode = sscanf(buf3+offset,"%ld",&value);
- if(rcode == 0)
- CDFWALK_put_message(S.MES_vid, input_error_mes,
- RINGBELL, NORMAL, PAUSE);
- } /* col_field = 2 */
- if(rcode)
- {
- /*
- Check and make sure that values entered were in range
- */
- if(field_num == 0)
- {
- if(type == INCREMENT)
- value = record_num + value;
- else if(type == DECREMENT)
- value = record_num - value;
- else if(col_field == 1)
- /*
- Decrement because using 1 instead of 0 on output line
- */
- value = value - 1;
- /*
- Check record
- */
- if(value >= 0 && value <= C.max_record_num)
- record_num = value;
- else
- {
- strcpy(mes, record_error_mes);
- sprintf(buf, "%6ld", C.max_record_num+1);
- strcat(mes, buf);
- CDFWALK_put_message(S.MES_vid, mes, RINGBELL, NORMAL,
- NOPAUSE);
- }
- } /* field_num == 0 */
- else
- {
- if(type == INCREMENT)
- value = indices[field_num-1] + value;
- else if(type == DECREMENT)
- value = indices[field_num-1] - value;
- else if(col_field == 1)
- /*
- Decrement because using 1 instead of 0 on output line
- */
- value = value - 1;
- /*
- Check indice
- */
- if(value >= 0 && value <= C.dim_sizes[field_num-1]-1)
- indices[field_num-1]=value;
- else
- {
- strcpy(mes, indices_error_mes);
- sprintf(buf, "%6ld", C.dim_sizes[field_num-1]);
- strcat(mes, buf);
- CDFWALK_put_message(S.MES_vid, mes,
- RINGBELL, NORMAL, NOPAUSE);
- }
- } /* field_num = 1 */
- }
- CDFWALK_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
- if(V.data_type == CDF_EPOCH && col_field == 0)
- label_border(S.WALK_vid, WALK_label, strlen(WALK_label));
- break;
- case NEWVAR:
- case newvar:
- if(C.num_vars <= CDFWALK_MAX_VARS_SCREEN)
- CDFWALK_put_message(S.MES_vid, noscroll_mes,
- RINGBELL, NORMAL, PAUSE);
- else
- /*
- Scroll in a new set page of variables
- */
- CDFWALK_scroll_var(screen, CDF, variables, VAR_display,
- &var_index, data_values, curr_field);
- CDFWALK_clear_row(S.MES_vid, MES_display, 1, 1, MES_COLUMNS-COL_OFFSET);
- update_keydef = TRUE;
- break;
- case KB_CTRL_F:
- CDFWALK_field_menu(screen, curr_field);
- update_keydef = TRUE;
- break;
- case KB_CTRL_P:
- /*
- Select values from a pop-up if positioned into a value and dimension field
- */
- var_num = C.dim_var_num[field_num];
- if(col_field == 0 && V.num_values <= MAX_VALUES)
- {
- DIS_display = (struct vid_struct *)
- malloc(V.num_values * sizeof(struct vid_struct));
- if(DIS_display != NULL)
- {
- /*
- Load in the values in the virtual display
- */
-
-
- if(V.data_type == CDF_EPOCH)
- num_bytes = EPOCH_WIDTH;
- else
- num_bytes =
- V.data_type == CDF_CHAR || V.data_type == CDF_UCHAR ?
- V.num_bytes+1 : MINMAX_SIZE;
- CDFWALK_load_discrete(V.char_value, V.num_values,
- num_bytes, DIS_display, &dis_rows, &dis_cols);
- #ifdef vms
- change_virtual_display(dis_rows, dis_cols,
- S.DIS_vid, BORDER, BOLD);
- #endif
- #if defined(unix) | defined(__MSDOS__)
- change_virtual_display(dis_rows, dis_cols,
- &S.DIS_vid, BORDER, BOLD);
- #endif
- /*
- Select desired value
- */
- CDFWALK_Menu_keydef(screen);
- CDFWALK_select_menu_item(S.DIS_vid,
- S.MES_vid, &val_num, DIS_display,
- V.num_values, dis_rows, dis_cols,
- DIS_ROW_PASTE, DIS_COL_PASTE, MENU, &tcode);
- if(tcode == KB_RETURN)
- {
- if(field_num == 0)
- record_num = val_num-1;
- else
- indices[field_num-1] = val_num-1;
- }
- free(DIS_display);
- }
- update_keydef = TRUE;
- } /* display null */
- else
- CDFWALK_put_message(S.MES_vid, to_many_mes,
- RINGBELL, NORMAL, PAUSE);
- break;
- case KB_REDRAW:
- repaint_screen();
- break;
- }
- }
- unpaste_virtual_display(S.WALK_vid);
- CDFWALK_free_STRING(variables, C.num_vars, data_values);
- }
- void CDFWALK_scroll_var(screen, CDF, variables, VAR_display, var_index,
- data_values, field_num)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- struct variable_struct *variables;
- struct vid_struct *VAR_display;
- long int *var_index;
- union mixed data_values[];
- long int *field_num;
- {
- int tcode;
- static char scroll_mes[] =
- "Press UP/DOWN arrow key to scroll thru variable list, RETURN when ready";
- #if defined(unix) | defined(__MSDOS__)
- begin_display_update(S.VARSCROLL_vid);
- #endif
- load_vid(S.VARSCROLL_vid, VARSCROLL_display, 0, VARSCROLL_NUM_ELEMENTS,
- NO_label);
- paste_virtual_display(S.VARSCROLL_vid, VARSCROLL_ROW_PASTE,
- VARSCROLL_COL_PASTE);
- #if defined(unix) | defined(__MSDOS__)
- end_display_update(S.VARSCROLL_vid);
- #endif
- CDFWALK_scroll_keydef(screen);
- CDFWALK_put_message(S.MES_vid, scroll_mes, NOBELL, NORMAL, NOPAUSE);
- tcode = NOTTHERE;
- while(tcode != KB_RETURN)
- {
- set_cursor_abs(S.VARSCROLL_vid, 1, 34);
- #ifdef vms
- read_input(&tcode);
- #endif
- #if defined(unix) | defined(ultrix) | defined(__MSDOS__)
- read_input(S.VARSCROLL_vid, &tcode);
- #endif
- switch (tcode)
- {
- /*
- calculate a new starting variable number to display
- */
- case KB_UPARROW:
- (*var_index)++;
- if(*var_index == C.num_vars)*var_index = 0;
- break;
- case KB_DOWNARROW:
- (*var_index)--;
- if(*var_index < 0)*var_index = C.num_vars-1;
- break;
- case PAGEUP:
- case PAGEup:
- (*var_index)-=CDFWALK_MAX_VARS_SCREEN;
- if(*var_index < 0)*var_index = 0;
- break;
- case PAGEDOWN:
- case PAGEdown:
- (*var_index)+=CDFWALK_MAX_VARS_SCREEN;
- if(*var_index >= C.num_vars)*var_index = C.num_vars - CDFWALK_MAX_VARS_SCREEN;
- break;
- case KB_REDRAW:
- repaint_screen();
- break;
- case KB_CTRL_F:
- CDFWALK_field_menu(screen, field_num);
- if(field_num != WALK_FIELD)tcode = KB_RETURN;
- break;
- case KB_PAD_ENTER:
- tcode = KB_RETURN;
- break;
- }
- /*
- Display the new page of variables and data
- */
- CDFWALK_load_var(screen, CDF, variables, VAR_display,
- *var_index, data_values);
- }
- unpaste_virtual_display(S.VARSCROLL_vid);
- }
- void CDFWALK_print_data(screen, select, VAR_display, field_num, var_num,
- data_values, walker_only)
- struct GLOBAL_struct *screen;
- struct variable_struct select[];
- struct vid_struct *VAR_display;
- long int field_num;
- long int var_num;
- union mixed data_values[];
- int walker_only;
- {
- long int len;
- long int /*i, */ j;
- double value;
- char var_data[15];
- char dim_data[25];
- CDFstatus rcode;
- static char time_error[] = "TIME ERROR ";
- extern char *epochString();
-
-
- for(j=0; j<15; j++)var_data[j] = ' ';
- for(j=0; j<25; j++)dim_data[j] = ' ';
- if(select[var_num].data_type == CDF_EPOCH)
- {
- ep.tSince0 = data_values[var_num].r8;
- strcpy(dim_data, epochString(&ep));
- rcode = epochParse(dim_data, &ep);
- if(rcode)
- {
- sprintf(var_data,"%04ld%02ld%02ld%02ld%02ld%02ld",ep.year,
- ep.month,
- ep.day,
- ep.hour,
- ep.minute,
- ep.second);
- var_data[14] = '\0';
- }
- else
- strcpy(var_data, time_error);
- }
- else if(select[var_num].data_type == CDF_CHAR ||
- select[var_num].data_type == CDF_UCHAR)
- {
- remove_trail(data_values[var_num].string);
- len = strlen(data_values[var_num].string);
- if(select[var_num].dim_variable || select[var_num].record_variable)
- {
- /*
- Variable is the first to vary with a dimension, will be displayed in the
- WALK window
- */
- if(len > 24)
- {
- /*
- 24 character limit, truncate
- */
- strncpy(dim_data, data_values[var_num].string, 22);
- dim_data[22] = '\0';
- strcat(dim_data,"..");
- }
- else
- strcpy(dim_data+(24-len), data_values[var_num].string);
- }
- /*
- Display variable only in VAR window
- */
- if(len > 14)
- {
- /*
- 14 character limit, truncate
- */
- strncpy(var_data, data_values[var_num].string, 12);
- var_data[12] = '\0';
- strcat(var_data,"..");
- }
- else
- strcpy(var_data+(14-len), data_values[var_num].string);
- }
- else
- {
- switch(select[var_num].data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- value = (double) data_values[var_num].r4;
- if(value < -1.e12 || value > 1.e12)
- sprintf(var_data," %13.6e",value);
- else
- sprintf(var_data," %13.*f",precision(value),value);
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- value = data_values[var_num].r8;
- if(value < -1.e12 || value > 1.e12)
- sprintf(var_data," %13.6e",value);
- else
- sprintf(var_data," %13.*f",precision(value),value);
- break;
- case CDF_INT4:
- sprintf(var_data," %11ld",data_values[var_num].i4);
- break;
- case CDF_UINT4:
- sprintf(var_data," %10lu",data_values[var_num].ui4);
- break;
- case CDF_INT2:
- sprintf(var_data," %6d",data_values[var_num].i2);
- break;
- case CDF_UINT2:
- sprintf(var_data," %6u",data_values[var_num].ui2);
- break;
- case CDF_BYTE:
- case CDF_INT1:
- sprintf(var_data," %4d",data_values[var_num].byte);
- break;
- case CDF_UINT1:
- sprintf(var_data," %3u",data_values[var_num].ubyte);
- }
- if(select[var_num].dim_variable || select[var_num].record_variable)
- {
- strncpy(dim_data+10, var_data, 14);
- dim_data[24] = '\0';
- }
- }
- /*
- Now display the data
- */
- if((select[var_num].dim_variable || select[var_num].record_variable) ||
- (walker_only))
- put_chars(S.WALK_vid, dim_data, 24, select[var_num].dim_num+1, 10,
- NOERASE, NORMAL);
- if(!walker_only)
- CDFWALK_put_selection(S.VAR_vid, VAR_display,
- field_num+(VAR_NUM_ELEMENTS/2), var_data, 14, NORMAL);
- }
- void remove_trail(str)
- char *str;
- {
- long int len;
- len = strlen(str);
- str+= len-1;
- while(*str == ' ')str--;
- *(str+1) = '\0';
- }
- void CDFWALK_load_var(screen, CDF, variables, VAR_display, index, data_values)
- struct GLOBAL_struct *screen;
- struct CDF_struct *CDF;
- struct variable_struct *variables;
- struct vid_struct *VAR_display;
- long int index;
- union mixed data_values[];
- {
- long int var_num;
- long int num_elements;
- long int num;
- long int dim_num;
- num = 0;
- if(C.num_vars > CDFWALK_MAX_VARS_SCREEN)
- {
- for(dim_num = 0; dim_num <= C.num_dims; dim_num++)
- {
- if(C.num_per_dim[dim_num] > 0)
- CDFWALK_print_data(screen, variables, VAR_display, num,
- C.dim_var_num[dim_num], data_values, TRUE);
- }
- }
- num_elements=C.num_vars < VAR_NUM_ELEMENTS/2 ? C.num_vars : VAR_NUM_ELEMENTS/2;
- begin_display_update(S.VAR_vid);
- for(num=0; num < num_elements; num++)
- {
- var_num = num+index < C.num_vars ? num+index : num+index - C.num_vars;
- CDFWALK_put_selection(S.VAR_vid, VAR_display, num,
- V.var_mnemonic,CDFWALK_MAX_VAR_LENGTH, NORMAL);
- CDFWALK_print_data(screen, variables, VAR_display, num, var_num,
- data_values, FALSE);
- }
- end_display_update(S.VAR_vid);
- }
- void CDFWALK_get_data(CDF, select, num_select, record_num, indices,
- data_values)
- struct CDF_struct *CDF;
- struct variable_struct select[];
- long int num_select;
- long int record_num;
- long int indices[];
- union mixed data_values[];
-
- {
- long int i;
-
- for (i = 0; i < num_select; i++)
- {
- switch (select[i].data_type)
- {
- case CDF_REAL4:
- case CDF_FLOAT:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, &data_values[i].r4);
- break;
- case CDF_REAL8:
- case CDF_DOUBLE:
- case CDF_EPOCH:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, &data_values[i].r8);
- break;
- case CDF_INT4:
- case CDF_UINT4:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, &data_values[i].i4);
- break;
- case CDF_INT2:
- case CDF_UINT2:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, &data_values[i].i2);
- break;
- case CDF_BYTE:
- case CDF_INT1:
- case CDF_UINT1:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, &data_values[i].byte);
- break;
- case CDF_CHAR:
- case CDF_UCHAR:
- select[i].rcode = CDFvarGet(C.CDF_id, select[i].var_num,
- record_num, indices, data_values[i].string);
- data_values[i].string[select[i].num_bytes] = '\0';
- }
- }
- }
- void CDFWALK_alloc_STRING(select, num_select, data_values)
- struct variable_struct select[];
- long int num_select;
- union mixed data_values[];
- {
- long int i;
-
- for (i = 0; i < num_select; i++)
- {
- if(select[i].data_type == CDF_CHAR || select[i].data_type == CDF_UCHAR)
- /*
- If this is a STRING variable allocate a enough space in the union array
- to hold this variable
- */
- data_values[i].string = (char *) malloc(select[i].num_bytes+1);
- }
- }
- void CDFWALK_free_STRING(select, num_select, data_values)
- struct variable_struct select[];
- long int num_select;
- union mixed data_values[];
- {
- long int i;
- for(i=0; i<num_select; i++)
- {
- if(select[i].data_type == CDF_CHAR || select[i].data_type == CDF_UCHAR)
- free(data_values[i].string);
- }
- }
- void CDFWALK_walk_keydef(screen)
- struct GLOBAL_struct *screen;
- {
- char key_line1[KEY_COLUMNS-COL_OFFSET+1];
- char key_line2[KEY_COLUMNS-COL_OFFSET+1];
- /*
- Load up keypad definitions for selecting a menu item
- */
- key_line1[0] = '\0';
- key_line2[0] = '\0';
- strcat(key_line1,CNTRLM); strcat(key_line1, UP); strcat(key_line1, LEFTW);
- strcat(key_line1,Ides); strcat(key_line1, FORWARD);
- strcat(key_line2,CNTRLW);strcat(key_line2, DOWN); strcat(key_line2, RIGHTW);
- strcat(key_line2,Vdes); strcat(key_line2, BACKWARD);
- CDFWALK_load_keydef(S.KEY_vid, key_line1, key_line2);
- }
- void CDFWALK_Menu_keydef(screen)
- struct GLOBAL_struct *screen;
- {
- char key_line1[KEY_COLUMNS-COL_OFFSET+1];
- char key_line2[KEY_COLUMNS-COL_OFFSET+1];
- /*
- Load up keypad definitions for selecting a menu item
- */
- key_line1[0] = '\0';
- key_line2[0] = '\0';
- strcat(key_line1,CNTRLM); strcat(key_line1, UP);
- strcat(key_line1,PUP);strcat(key_line1,RET);strcat(key_line1, Qdes);
- strcat(key_line2,CNTRLW);strcat(key_line2, DOWN);
- strcat(key_line2,PDOWN);strcat(key_line2,HLP);
- CDFWALK_load_keydef(S.KEY_vid, key_line1, key_line2);
- }
- void CDFWALK_scroll_keydef(screen)
- struct GLOBAL_struct *screen;
- {
- char key_line1[KEY_COLUMNS-COL_OFFSET+1];
- char key_line2[KEY_COLUMNS-COL_OFFSET+1];
- /*
- Load up keypad definitions for selecting a menu item
- */
- key_line1[0] = '\0';
- key_line2[0] = '\0';
- strcat(key_line1,CNTRLM); strcat(key_line1,RET); strcat(key_line1, UP);
- strcat(key_line1,PUP);
- strcat(key_line2,CNTRLW);strcat(key_line2,DEL);strcat(key_line2, DOWN);
- strcat(key_line2,PDOWN);strcat(key_line1, HLP);
- CDFWALK_load_keydef(S.KEY_vid, key_line1, key_line2);
- }
- int init_var_display(display)
- struct vid_struct **display;
- {
- long int i;
- int row;
- int col_index;
- static int cols[] = { 2, 27, 52, 11, 36, 61 };
- row = 1;
- col_index = 0;
- *display = (struct vid_struct *)
- malloc(VAR_NUM_ELEMENTS * sizeof(struct vid_struct));
- if(*display == NULL)return(BAD_MALLOC);
-
- for(i=0; i<VAR_NUM_ELEMENTS; i++)
- {
- (*display)[i].row = row;
- (*display)[i].col = cols[col_index];
- (*display)[i].label[0] = '\0';
- if(row == 9)
- {
- row = 1;
- col_index++;
- }
- else
- row++;
- }
- return(0);
- }
-